package summerprojectFX.parser;
import java.io.File;

import summerprojectFX.model.Song;


public abstract class FileInputOutput {
	protected File file;
	
	public FileInputOutput(File file){
		this.file = file;
	}
	
	public abstract Song read();
	
	public Song createSong(String song) {
		Song newSong = new Song();
		String[] temp = song.split("[\\r\\n]+");
		boolean whitespace = true;
		int title = 0;
		while(whitespace == true){
                        
			if(temp[title].isEmpty() == false){
                            if(temp[title].contains("Chords ")){
                                String[] title1 = temp[title].split("Chords");
                                System.out.println(title1[0]);
                                
                                newSong.setTitle(title1[0]);
                                temp[title + 1] = "Chords " + title1[1] + "\n" + temp[title + 1];
                                break;
                             }else{
				newSong.setTitle(temp[title]);
				break;
                            }
			}
			title++;
		}
                
                String s = "";
                for(int i = title + 1; i < temp.length; i++){
                    s = s + temp[i];
                }
		
		String lyrics = "";
		for (int i = title + 1; i < temp.length; i++) {
			lyrics = lyrics + temp[i] + "\n";
		}
		newSong.setLyrics(lyrics);
		
		return newSong;
	}
	
	
}
